package com.guang.syncronized.review;

import org.openjdk.jol.info.ClassLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @Description 默认不开启偏向延迟。在进入到同步块中去会升级成轻量级锁
 *              证明：锁对象如果进入到同步块之前调用了hashcode方法，再加锁直接升级成轻量级锁
 * @Author liguang
 * @Date 2022/10/22/08:27
 */
public class SyncronziedReviewTestThree {

    private final static Logger logger = LoggerFactory.getLogger(SyncronziedReviewTestThree.class);

    static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        lock.hashCode();
        logger.info("打印当前对象的对象头，001.无锁不可偏向，{}",ClassLayout.parseInstance(lock).toPrintable());

        synchronized (lock){
            logger.info("打印当前对象的对象头，000不可偏向的偏向锁，{}",ClassLayout.parseInstance(lock).toPrintable());
        }
    }
}
